package sparrow.ui;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.*;

import sparrow.common.TopicHistory;
import sparrow.ui.nox.NoxFrame;
import sparrow.ui.nox.SystemPath;



public class ChatWindow extends NoxFrame {
	private static final Format fmTime = new SimpleDateFormat("HH:mm:ss");
	private ChatPane chatpane;
	
	public ChatWindow(TopicHistory th) {
		super("Sparrow", SystemPath.IMAGES_RESOURCE_PATH + "bkgrd.png", 
				SystemPath.LOGO_RESOURCE_PATH + "NoXlogo_20.png",
				SystemPath.LOGO_RESOURCE_PATH + "NoXlogo_48.png",
				SystemPath.LOGO_RESOURCE_PATH + "nox.png", true);
		chatpane = new ChatPane(th);

		this.getContainer().setLayout(new BoxLayout(this.getContainer(), BoxLayout.X_AXIS));
		this.getContainer().add(chatpane);
		
		pack();
		setSize(400,500);
		setVisible(true);
	}
	
	public void receiveMsg(String msg) {
		String time = fmTime.format(new Date());
		String[] split = msg.split(" *", 1);
		chatpane.incomingMsgProcessor(split[0], time, split[1], null);
	}
	
	/** Test stub */
	public static void main(String[] args) {
	    try {
		    // Set cross-platform Java L&F (also called "Metal")
	        UIManager.setLookAndFeel(
	            UIManager.getSystemLookAndFeelClassName());
	    } 
	    catch (UnsupportedLookAndFeelException e) {
	       // handle exception
	    }
	    catch (ClassNotFoundException e) {
	       // handle exception
	    }
	    catch (InstantiationException e) {
	       // handle exception
	    }
	    catch (IllegalAccessException e) {
	       // handle exception
	    }

		ChatWindow cw = new ChatWindow(new TopicHistory("blah"));
	}
}
